<%--
  Created by IntelliJ IDEA.
  User: 52203
  Date: 2018/12/28
  Time: 9:07
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <base href="<%=request.getContextPath()%>/"/>
    <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    <%@include file="../layUI.jsp"%>
</head>
<script type="text/javascript" src="static/js/jquery-2.1.1.min.js"></script>
<script type="text/javascript">
    var id ;
    /*显示数据*/
    $(function () {
        id='${param.id}';
        $.getJSON("/doBig",{"action":"selByID","id":id },callback);
        function callback(data) {
            $("[name=id]").val(data[0].bigId);
            $("[name=bigName]").val(data[0].bigName);
            $("[name=bigText]").val(data[0].bigText);
        }
    })
    /*保存信息*/
    function saves() {
        //非空验证
        var flag = true;
        $(".notNull").each(function () {
            var name = $(this).attr("name");
            if($(this).val()==""){
                alert($(this).attr('notNull')+"不能为空");
                flag =false;
                return;
            }
        })

        if(flag){
            //得到所有值，并转为字符串
            var queryString = $("form").serialize();
            $.getJSON("/doBig?action=bigUpdate&id="+id, queryString, callback);
            function callback(data) {
                if (data.flag == "true") {
                    alert("修改成功!");
                    location.href="/page/bigclass/bigQuery.jsp";
                } else {
                    alert("修改失败!");
                    location.href="/page/bigclass/bigUpdate.jsp";
                }
            }
        }
    }

</script>

<body>
    <form action="doBig?action=bigUpdate" method="post">
        大分类ID<input type="text" value="" name="id" readonly>
        大分类名称<input type="text" value="" name="bigName" class="notNull" notNull="大分类名称">
        大分类描述<input type="text" value="" name="bigText" class="notNull" notNull="大分类描述">
        <input type="button" value="修改完成" class="layui-btn" onclick="saves()">
    </form>
</body>
</html>
